<template>
  <!-- 客户信息查询 -->
  <Card>
	<div style="text-align:right" v-if="showAdd"> 
		<Uploadv 
          :action="updateUrl"
          :show-upload-list='false' :format="['pdf']"
          :multiple="true"
          name="multipartFile"
          :headers="headers"
		  :before-upload="beforeUpload"
          :on-success="uploadSuccess"
		  :on-error="uploadFail"
          style="display:inline-block">
          <Button type="primary" icon="ios-cloud-download-outline" >导入文件</Button>
        </Uploadv>
		</div>
	
    <Table :columns="columns" :data="tableData" style="margin-top:15px">
      <template slot-scope="{ row }" slot="operate">
		<!-- 可删除操作人为登录人的文件，其他人上传无法上传，该按钮置灰 -->
		<!-- <span class="table-button" @click="handelDel(row)">删除</span> -->
		<span v-if="useragentcode==row.operatorNo" class="table-button" @click="handelDel(row)">删除</span>
		<span v-else class="table-button" style="color:#ccc">删除</span>
        <span class="table-button" @click="handelDownload(row)" style="margin-left: 10px;">下载并查看</span>
      </template>
    </Table>

    <Page :total="ipagination.total" show-sizer show-total style="text-align:right;margin-top:20px"
      @on-change="handleCurrentChange" @on-page-size-change="handleSizeChange"
      :page-size-opts="ipagination.pageSizeOptions" :current="ipagination.pageIndex" :page-size="ipagination.pageSize"
      transfer></Page>

  </Card>
</template>

<script>
import {exportFile} from "../../util/util"
import { baseURL} from '../../util/url';
import { loadResourcesMixin } from "../../util/mixins/loadResourcesMixin";
import { tableChangeMixin } from "../../util/mixins/tableChangeMixin";
export default {
  name: "clientInfo",
  mixins: [loadResourcesMixin, tableChangeMixin],
  data() {
    return {
      mixinData: {
        tableAxios: "uerSchemeGetList",
      }, 
	  updateUrl:"/scrm-gateway/scrm-bhuer/api/uerScheme/upload",
	  headers: {
        "Authorization": sessionStorage.getItem('credentials')
      },  
	  showAdd:false,
	  useragentcode:'',   
      columns: [
        {
          title: "序号",
          type: "index",
          align: "center",
		  width:80
        },        
		{
          title: "导入文件",
          key: "attachmentName",
          align: "center",
        },
        {
          title: "导入时间",
          key: "createTime",
          align: "center",
        },
		{
          title: "操作人",
          key: "operatorName",
          align: "center",
		  width:100
        },
		{
          title: "操作",
          key: "operate",
		  slot: "operate",
          align: "center",
          width: "180",
          fixed: "right",
        },
      ],
    };
  },
  mounted() {
	let roleId=sessionStorage.getItem("roleId")
	if(roleId >=10 && roleId<=14){
		this.showAdd=true
	}
	this.useragentcode=sessionStorage.getItem('username')
  },
  methods: {
	handelDel(row){
		this.$Modal.confirm({
			title:"确定要删除吗",
			onOk: () => {
          		//点击确认的方法          
				this.api.uerSchemeDelete({ id: row.id}).then(res => {
				//console.log(res);
				if (res.code === 200) {
					this.$Message.success(res.msg);
					this.loadResources()
				} else {
					this.$Message.info(res.msg);
				}
			});
		},
		})
	},
	handelDownload(row){
		exportFile("scrm-gateway/scrm-uer/api/uerScheme/download?id="+row.id)
	},
	beforeUpload(file) {
      let hz = file.name.split(".");
      let extra = hz[hz.length - 1];
      if (extra != "pdf"      ) {
        this.$Message.info("请上传PDF格式的文件");
        return false;
      }
    },
    // 导入文件
    uploadSuccess(res){
      this.$Message.info({
        content: res.msg,
        duration:5
      })
	  this.loadResources()
    },
	// 连不到后端的情况
    uploadFail(response, file, fileList) {
      this.$Message.info("保存失败");
    },
   
  },
};
</script>